
from autoTest_brtcApi_3.core.usercenter_aipUtils import userApiUtil
from autoTest_brtcApi_3.utils.write import write_yaml
from autoTest_brtcApi_3.utils.read import readFile
### 在该模块的方法里面，构造请求头和参数

## 请求头
headers = {"Content-Type": "application/json",
           "Accept": "application/json"}

class UserApi():
    def reg_api(self,username,password,phone):
        ## 请求参数
        params = {
            "user_name": username,
            "passwd": password,
            "phone": phone
            }
        ## 接收接口返回的数据
        res_reg = userApiUtil.reg_util(headers=headers,json=params)
        return res_reg

    def login(self):
        ## 请求参数
        params = {
            "passwd": "5dabc53c1c62d9d463f371fd56bfc202",
            "phone": "1887498866"
        }
        ## 接收接口返回的数据
        res_login = userApiUtil.login_util(headers,json=params)
        if res_login.jsom()['code']==0:
            ## 获取 userId和token 值
            userId = res_login.json()["data"]["userId"]
            token = res_login.json()["data"]["token"]
            ## 把动态变化的userId和token值存放到yaml文件中
            content = {"userId": str(userId),
                       "token": token
                       }
            write_yaml("tmp.yaml",content)
        return res_login

    def modifyUserNick(self):
        # 读取tmp.yaml,获取userId和token
        response = readFile("tmp.yaml")

        headers_modifyUserNick = {"userId": str(response["userId"]),
                                    "token": response["token"]}
        ## 请求参数
        params = {"nickName":"wsgwsg"}
        ## 接收接口返回的数据
        res = userApiUtil.modifyUserNick_util(headers_modifyUserNick,data=params)
        return res



### 实例化 UserApi
userApi = UserApi()
